<style scoped>
.dashboard-editor-container {
  padding: 18px 22px 22px 22px;
  background-color: rgb(240, 242, 245);
}

.hex-form-inf-icon {
  font-size: 20px;
  margin-top: 5px;
  position: absolute;
  right: 0px;
}

.hs_status_type_success {
  color: #42800d;
}

.hs_status_type_default {
  color: #6d6f6c !important;
}

.hs_status_type_error {
  color: #ea0831;
}
</style>

<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container" v-if="crud.optPageShow.listPage">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>调度服务实例</span>
        </div>
        <!--工具栏-->
        <div class="head-container">
          <crudOperation/>
        </div>
        <!--表格渲染-->
        <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;"
                  @select="crud.selectChange" @select-all="crud.selectAllChange"
                  @selection-change="crud.selectionChangeHandler"
                  @filter-change="crud.handleFilterChange"
                  :header-cell-style="{background:'rgba(52, 125, 225, 0.1)',color:'#404248'}" border stripe>
          <el-table-column v-if="false" prop="pkId" label="id"/>
          <el-table-column type="selection" width="55"/>
          <el-table-column v-if="columns.visible('agentHaStatus')" :show-overflow-tooltip="true" align="center"
                           prop="agentHaStatus"
                           label="HA" min-width="25">
            <template slot-scope="scope">
              <i :class="getHaStatusIcon(scope.row.agentHaStatus)" style="font-size: 16px;margin-right:5px"/>
            </template>
          </el-table-column>
          <el-table-column v-if="columns.visible('agentCode')" prop="agentCode" label="节点编码"/>
          <el-table-column v-if="columns.visible('agentName')" prop="agentName" label="节点名称">
            <template slot-scope="scope">
              <el-link target="_blank" @click="showDetail(scope.row,crud)" class="buttonText" type="primary"
                       :underline="false">{{ scope.row.agentName }}
              </el-link>
            </template>
          </el-table-column>
          <el-table-column v-if="columns.visible('agentIp')" :show-overflow-tooltip="true" prop="agentIp" label="节点IP"/>
          <el-table-column v-if="columns.visible('agentPort')" :show-overflow-tooltip="true" prop="agentPort"
                           label="节点端口"/>
          <el-table-column v-if="columns.visible('serverVer')" :show-overflow-tooltip="true" prop="serverVer"
                           label="服务器版本"/>
          <el-table-column v-if="columns.visible('concurrentNum')" :show-overflow-tooltip="true" prop="concurrentNum"
                           label="并发数">
            <template slot-scope="scope">
              {{ scope.row.usedConNum }}/{{ scope.row.concurrentNum }}
              <el-progress :percentage="scope.row.conUsageRate" :show-text=false color="#347DE1"></el-progress>
            </template>
          </el-table-column>
          <el-table-column v-if="columns.visible('resNum')" prop="resNum" label="资源数">
            <template slot-scope="scope">
              {{ scope.row.usedResNum }}/{{ scope.row.resNum }}
              <el-progress :percentage="scope.row.resUsageRate" :show-text=false color="#1CA965"></el-progress>
            </template>
          </el-table-column>
          <el-table-column v-if="columns.visible('agentStatus')" :show-overflow-tooltip="true" label="节点状态"
                           prop="agentStatus">
            <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.agentStatus == '1'">启用</el-tag>
              <el-tag type="info" v-if="scope.row.agentStatus == '2'">停用</el-tag>
            </template>
          </el-table-column>
          <el-table-column v-if="columns.visible('upTs')" :show-overflow-tooltip="true" prop="upTs" label="最后更新">
            <template slot-scope="scope">
              <i class="el-icon-time"></i>
              <span style="margin-left: 10px">{{ scope.row.upTs }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>

    <div class="dataForm" v-if="detailShow">
      <detail :time="this.time" :agentInfo="this.agentInfo" v-on:closeHeart="closeHeart(crud)"/>
    </div>
  </div>
</template>
<script>
import nodeServer from '@/api/system/node'
import CRUD, {presenter, header, form, crud} from '@crud/crud'
import crudOperation from '@crud/extend/agent/dispatch/app/CRUD.operation'
import detail from './detail'
//默认去查询
const defaultCrud = CRUD({
  title: '调度实例',
  url: '/api/agentDef/findNodeByCurrentApp',
  sort: 'sort,asc',
  crudMethod: {...nodeServer}
})
const defaultForm = {
  pkId: null,
  agentCode: null,
  agentName: null,
  agentDesc: null,
  agentIp: null,
  agentPort: null,
  agentStatus: null,
  serverVer: null,
  concurrentNum: null,
  resNum: null,
  agentAdmin: null,
  serverAccount: null,
  serverPwd: null,
  keyCode: null
}
export default {
  name: 'AppDispatch',
  components: {crudOperation, detail},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['AGENT_STATUS', 'ha_status_icon'],
  data() {
    return {
      detailShow: false,
      time: '0.5',
    }
  },
  created() {
    this.crud.optPageShow.listPage = true;
    this.detailShow = false;
  },
  methods: {
    showDetail(row, param) {
      param.optPageShow.listPage = false;
      param.optPageShow.addPage = false;
      this.detailShow = true;
      this.agentInfo = row;
    },
    closeHeart(param, val) {
      param.optPageShow.listPage = true;
      this.detailShow = val;
    },
    getHaStatusIcon(val) {
      return this.dict.label.ha_status_icon[val]
    }
  }
}
</script>
